package com.qf.day09.work3;

import java.util.Objects;
import java.util.Random;

public class Hero implements Fightable{
    private String name;
    private int harm; //攻击力
    private int life; //生命值

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getHarm() {
        return harm;
    }

    public void setHarm(int harm) {
        this.harm = harm;
    }

    public int getLife() {
        return life;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public Hero() {
    }

    public Hero(String name, int life) {
        this.name = name;
        this.life = life;
    }

    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                ", harm=" + harm +
                ", life=" + life +
                '}';
    }

    @Override
    public boolean isAlive() {
        if(this.life>0){
            return true;
        }
        return false;
    }

    @Override
    public void fight(Fightable enemy) {
        Random random = new Random();
        int harm =  random.nextInt(10)+1;
        this.setHarm(harm);

    }

    @Override
    public void takeDamage(int damage) {
        this.life-=damage;
    }

    /**
     *重写equals方法
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;
        }
        if(obj instanceof Hero){
            Hero hero = (Hero) obj;
            if(hero.getName()==this.getName() && hero.getLife()==this.getLife() && hero.getHarm()== hero.getHarm()){
                return true;
            }
        }
        return false;
    }
}
